Current File : //usr/lib/python3/dist-packages/twisted/python/test/__pycache__/test_fakepwd.cpython-312.pyc |
�
Ϫ�f[; � �4 � d Z ddlZeZ ddlZeZddlZddlmZ ddl m
Z
ddlmZm
Z
ddlmZ dZd� Z e� Z G d � d
� Z G d� dee� Z G d
� dee� Z G d� d� Z G d� dee� Z G d� dee� Zy# e$ r dZY �w xY w# e$ r dZY ��w xY w)z&
Tests for L{twisted.python.fakepwd}.
� N)�getitem)�_PYPY)�ShadowDatabase�UserDatabase)�TestCasei� c �x � t } t � t j | � | dz } �| S # t $ r Y | S w xY w)a�
By convention, UIDs less than 1000 are reserved for the system. A system
which allocated every single one of those UIDs would likely have practical
problems with allocating new ones, so let's assume that we'll be able to
find one. (If we don't, this will wrap around to negative values and
I{eventually} find something.)
@return: a user ID which does not exist on the local system. Or, on
systems without a L{pwd} module, return C{SYSTEM_UID_MAX}.
� )�SYSTEM_UID_MAX�pwd�getpwuid�KeyError)�guesss �B/usr/lib/python3/dist-packages/twisted/python/test/test_fakepwd.py�findInvalidUIDr sT � �
�E�
���
����U�#� ��
��
� �L�� �
�� �L�
�s �, � 9�9c �: � e Zd ZdZd� Zd� Zd� Zd� Zd� Zd� Z d� Z
y )
�UserDatabaseTestsMixina^
L{UserDatabaseTestsMixin} defines tests which apply to any user database
implementation. Subclasses should mix it in, implement C{setUp} to create
C{self.database} bound to a user database instance, and implement
C{getExistingUserInfo} to return information about a user (such information
should be unique per test method).
c � � t d� D ]� }| j � \ }}}}}}}| j j |� } | j | j
|� | j | j |� | j | j |� | j | j |� | j | j |� | j | j |� | j | j |� �� y)zc
I{getpwuid} accepts a uid and returns the user record associated with
it.
� N)�range�getExistingUserInfo�databaser �assertEqual�pw_name� pw_passwd�pw_uid�pw_gid�pw_gecos�pw_dir�pw_shell�
�self�i�username�password�uid�gid�gecos�dir�shell�entrys
r �
test_getpwuidz$UserDatabaseTestsMixin.test_getpwuidC s� � �
�q�� 4�A�>B�>V�>V�>X�;�H�h��S�%��e� �M�M�*�*�3�/�E����U�]�]�H�5����U�_�_�h�7����U�\�\�3�/����U�\�\�3�/����U�^�^�U�3����U�\�\�3�/����U�^�^�U�3� 4� c �b � | j t | j j t � y)zu
I{getpwuid} raises L{KeyError} when passed a uid which does not exist
in the user database.
N)�assertRaisesr
r r �INVALID_UID�r! s r �test_noSuchUIDz%UserDatabaseTestsMixin.test_noSuchUIDV s � �
���(�D�M�M�$:�$:�K�Hr, c � � t d� D ]� }| j � \ }}}}}}}| j j |� } | j | j
|� | j | j |� | j | j |� | j | j |� | j | j |� | j | j |� | j | j |� �� y)zh
I{getpwnam} accepts a username and returns the user record associated
with it.
r N)r r r �getpwnamr r r r r r r r r s
r �
test_getpwnamz$UserDatabaseTestsMixin.test_getpwnam] s� � �
�q�� 4�A�>B�>V�>V�>X�;�H�h��S�%��e� �M�M�*�*�8�4�E����U�]�]�H�5����U�_�_�h�7����U�\�\�3�/����U�\�\�3�/����U�^�^�U�3����U�\�\�3�/����U�^�^�U�3� 4r, c �v � t }t rt }| j || j j
d� y)zN
L{getpwnam} rejects a non-L{str} username with an exception.
�
i-am-bytesN)� TypeErrorr � Exceptionr. r r3 )r! �exc_types r �test_getpwnamRejectsBytesz0UserDatabaseTestsMixin.test_getpwnamRejectsBytesp s/ � � ��� !�H����(�D�M�M�$:�$:�M�Jr, c �Z � | j t | j j d� y)zz
I{getpwnam} raises L{KeyError} when passed a username which does not
exist in the user database.
z.nosuchuserexiststhenameistoolongandhasinittooN)r. r
r r3 r0 s r �test_noSuchNamez&UserDatabaseTestsMixin.test_noSuchName{ s'